package cn.com.guage.dtm.jubian;
import java.util.*;

import java.util.*;

public class JSON格式合法性检查 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder jsonBuilder = new StringBuilder();
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.trim().isEmpty()) {
                break;
            }
            jsonBuilder.append(line);
        }
        String json = jsonBuilder.toString();
        System.out.println(validateJson(json));
    }

    public static String validateJson(String json) {
        Set<Integer> errors = new TreeSet<>();
        Stack<Character> stack = new Stack<>();
        boolean inQuotes = false;

        for (int i = 0; i < json.length(); i++) {
            char c = json.charAt(i);
            if (c == '"') {
                if (inQuotes) {
                    stack.pop();
                    inQuotes = false;
                } else {
                    stack.push(c);
                    inQuotes = true;
                }
            } else if (!inQuotes) {
                if (c == '[') {
                    stack.push(c);
                } else if (c == ']') {
                    if (stack.isEmpty() || stack.pop() != '[') {
                        errors.add(1);
                    }
                } else if (c == '{') {
                    stack.push(c);
                } else if (c == '}') {
                    if (stack.isEmpty() || stack.pop() != '{') {
                        errors.add(2);
                    }
                }
            }
        }

        if (inQuotes) {
            errors.add(3);
        }

        while (!stack.isEmpty()) {
            char top = stack.pop();
            if (top == '[') {
                errors.add(1);
            } else if (top == '{') {
                errors.add(2);
            } else if (top == '"') {
                errors.add(3);
            }
        }

        for (int i = 0; i < json.length() - 1; i++) {
            char c1 = json.charAt(i);
            char c2 = json.charAt(i + 1);
            if ((c1 == '}' || c1 == ']') && c2 != ',' && c2 != '}' && c2 != ']') {
                errors.add(4);
            }
        }

        StringBuilder result = new StringBuilder();
        for (int error : errors) {
            result.append(error);
        }
        return result.length() == 0 ? "0" : result.toString();
    }
}